package com.springboot.config.primary;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

/**
 * UserRepository
 * user数据操作接口
 * @author jlicc
 * @create 2017-03-14-16:43
 **/

@CacheConfig(cacheNames = "users")
public interface UserRepository extends JpaRepository<User, Long> {

    @Cacheable(cacheNames = "users1",key = "2000")
    User findByName(String name);

    @CachePut(cacheNames = "users1",key = "2000")
    User save(User user);

    @CacheEvict(cacheNames = "users1",key = "2000") //allEntries = true 删除全部缓存数据
    void delete(Long id);
}
